﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Principal;

namespace IndexingService
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            WindowsIdentity user = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(user);
            if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                MessageBox.Show("Ran as non Administrator... Trying to assume control");
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute = true;
                startInfo.WorkingDirectory = Environment.CurrentDirectory;
                startInfo.FileName = Application.ExecutablePath;
                startInfo.Verb = "runas";
                try
                {
                    Process proc = Process.Start(startInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    MessageBox.Show("Something got fucked up when trying to assume Administrator Control... Sorry :S");                    
                }
                finally
                {
                    Application.Exit();
                    Environment.Exit(0);
                }
            }

            // Read in config file
            ConfigReader cr = new ConfigReader();
            cr.ConfigFile = @"C:\Users\Dani\Documents\Visual Studio 2010\Projects\IndexingService\config.xml";
            cr.load();


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form f = new formIndexMain();
            Application.Run(f);
        }
    }
}
